/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package linkedlistdependentqueue;

/**
 *
 * @author mweya
 */
import linkedlistdependentqueue.NoSuchElementException;
import linkedlistdependentqueue.LinkedList;
public class Queue<AnyType> {
    LinkedList queue = new LinkedList<>();
    
    public Queue() {
        
    }
    
    public Queue(AnyType data) {
        queue.addItem(data);
    }
    
    public void add(AnyType data) {
        // This data is literally being passed along from main
        // to queue to linked list to node.
        queue.addItem(data);
    }
    
        public void enqueue(AnyType data) {
        queue.addItem(data);
    }
    
    public boolean offer(AnyType data) {
        try {
            queue.addItem(data);
            return true;
        } catch (Exception e) {
            // This will literally never happen
            return false;
        }
    }
    
    public AnyType peek() {
        return (AnyType) queue.get(0);
    }
    
    public AnyType element() throws NoSuchElementException {
        if (queue.size() < 1) {
            throw new NoSuchElementException();
        } else {
            return (AnyType) queue.get(0);
        }
    }
    
    public AnyType dequeue() {
        if (queue.size() < 1) {
            return (AnyType) null;
        } else {
            AnyType response = (AnyType) queue.get(0);
            Node notneededbutimtoolazytocopypastethemethodandmakeitvoid = queue.delete(0);
            return response;
        }
    }
    
    public AnyType poll() {
        if (queue.size() < 1) {
            return (AnyType) null;
        } else {
            AnyType response = (AnyType) queue.get(0);
            Node notneededbutimtoolazytocopypastethemethodandmakeitvoid = queue.delete(0);
            return response;
        }
    }
    
    public AnyType remove() throws NoSuchElementException {
        if (queue.size() < 1) {
            throw new NoSuchElementException();
        } else {
            AnyType response = (AnyType) queue.get(0);
            Node notneededbutimtoolazytocopypastethemethodandmakeitvoid = queue.delete(0);
            return response;
        }
    }
    
    public int size() {
        return queue.size();
    }
    
    public void clear() {
        queue = new LinkedList();
    }
    
   @Override
    public String toString() {
        String out = "Queue:\n";
        out = out+queue.toString();
        return out;
    }
}